package com.qfedu.config;

import com.mchange.v2.c3p0.ComboPooledDataSource;
import org.apache.commons.dbutils.QueryRunner;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.annotation.Scope;

import javax.sql.DataSource;
@Configuration
@PropertySource(value = "classpath:jdbc.properties")

public class JdbcConfig {
    @Value("${driverClass}")   
    private String driverClass;
    @Value("${jdbcUrl}")
    private String jdbcUrl;
    @Value("${user}")
    private String user;
    @Value("${password}")
    private String password;

//
//    @Bean(name = "runner")
//    @Scope("prototype")
//    public QueryRunner queryRunner(){return new QueryRunner(dataSource());
//
//    }
//    @Bean
//    public DataSource dataSource(){
//        DataSource dataSource = new ComboPooledDataSource();
//        try {
//            ((ComboPooledDataSource) dataSource).setDriverClass(driverClass);
//            ((ComboPooledDataSource) dataSource).setJdbcUrl(jdbcUrl);
//            ((ComboPooledDataSource) dataSource).setUser(user);
//            ((ComboPooledDataSource) dataSource).setPassword(password);
//            return dataSource;
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//
//        return dataSource;
//    }

}
